home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 1 of 3 / CHAPTE20 / EX8.C < prev    next >
C/C++ Source or Header  |  1995-03-22  |  3KB  |  64 lines

  1. #include <genstub.c>
  2.  
  3. #define EDIT_ID       1000   // Identifies the child window.
  4.  
  5. LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  6. {
  7.    switch (uMsg) 
  8.    {
  9.          case WM_CREATE:        // Create an edit box control to manipulate section contents.
  10.             {
  11.                TCHAR szBuffer[256];
  12.                LPTSTR lpTemp = szBuffer; 
  13.                LRESULT lRetVal = DefWindowProc( hWnd, uMsg, wParam, lParam );
  14.                wsprintf( lpTemp, "FirstKey = %d", 1 );
  15.                lpTemp += lstrlen(lpTemp) + 1;
  16.                wsprintf( lpTemp, "SecondKey = %s", "Two" );
  17.                lpTemp += lstrlen(lpTemp) + 1;
  18.                *lpTemp = 0;
  19.                WritePrivateProfileSection( "TestSection",     // section
  20.                                            szBuffer, // buffer
  21.                                            "YOUR.INI" );      // INI file name
  22.                return lRetVal;
  23.             } 
  24.             case WM_COMMAND:       // process menu items 
  25.                  switch ( LOWORD( wParam )  )
  26.                  {
  27.                      case IDM_TEST: 
  28.                         {
  29.                               int iRow = 0;
  30.                               HDC hDC = GetDC( hWnd );
  31.                               LPTSTR lpIniValuesBuffer = HeapAlloc( GetProcessHeap(),
  32.                                                                     HEAP_ZERO_MEMORY,
  33.                                                                     256 );
  34.                               LPTSTR lpTemp = lpIniValuesBuffer;
  35.                               GetPrivateProfileSection( "TestSection",       // Section name
  36.                                                         lpIniValuesBuffer,   // Buffer
  37.                                                         256,                 // Buffer size
  38.                                                         "YOUR.INI" );        // INI file name.
  39.                               while (*lpTemp) 
  40.                               {
  41.                                   TextOut( hDC, 0, iRow++ * 20, lpTemp, lstrlen(lpTemp) );
  42.                                   lpTemp += lstrlen(lpTemp) + 1;
  43.                               } 
  44.                               HeapFree( GetProcessHeap(), 0L, lpIniValuesBuffer );
  45.                               ReleaseDC( hWnd, hDC );
  46.                         }
  47.                      break;
  48.                   case IDM_EXIT:
  49.                      DestroyWindow( hWnd );
  50.                      break;
  51.                   }
  52.                   break;
  53.  
  54.       case WM_DESTROY: 
  55.              PostQuitMessage( 0 );
  56.       break;
  57.       default:
  58.          return DefWindowProc( hWnd, uMsg, wParam, lParam );
  59.    }
  60.    return( 0L ) ;
  61. }
  62.  
  63. #include <about.c>
  64.